﻿Imports System.Data.OleDb
Public Class AddShop
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Set the Calendar date to today by default
        If Not IsPostBack Then
            e_ShopLastReviewDate.SelectedDate = DateTime.Now.Date()
        End If
    End Sub




    Protected Sub btn_AddShop_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_AddShop.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newPhotoName = myGUID.ToString() + ".jpg"

        If f_Photo.HasFile Then
            f_Photo.SaveAs(Request.MapPath("~/Pictures") & "/" & newPhotoName)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringRestaurants").ConnectionString)
        Dim SqlString As String = "Insert into Shops(ShopName,PostCode,Description,Photo,Rating,LastReviewDate,URL,UserName) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_ShopName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_PostCode.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f4", "~/Pictures/" & newPhotoName)
        cmd.Parameters.AddWithValue("@f5", rbl_Rating.SelectedValue)
        cmd.Parameters.AddWithValue("@f6", tb_ShopLastReviewDate.Text)
        cmd.Parameters.AddWithValue("@f7", tb_URL.Text)
        cmd.Parameters.AddWithValue("@f8", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("~/confirmation.aspx")



    End Sub
End Class